package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Company;
import edu.hwadee.service.CompanyService;

public class CompanyServiceImpl extends BasicServiceImpl implements CompanyService {

	@Override
	public Integer save(Company company) {
		try {
			return getCompanyDAO().save(company);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean delete(Company company) {
		try {
			getCompanyDAO().delete(company);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Company> search(Company company) {
		try {
			return (List<Company>)getCompanyDAO().findByExample(company);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Company searchById(Integer companyId) {
		try {
			return getCompanyDAO().findById(companyId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Company company) {
		try {
			if(searchById(company.getCompanyId()) != null) {
				getCompanyDAO().merge(company);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Company> showAll() {
		try {
			return (List<Company>)getCompanyDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
